﻿using AIO.Entity.DataInit;
using Microsoft.EntityFrameworkCore;

namespace AIO.Entity.Base
{
    public class ApiDBContext : DbContext
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="opts"></param>
        public ApiDBContext(DbContextOptions<ApiDBContext> opts) : base(opts)
        {

        }
        /// <summary>
        /// 年级
        /// </summary>
        public DbSet<Department> Department { get; set; }
        /// <summary>
        /// 学生
        /// </summary>
        public DbSet<Student> Students { get; set; }

        /// <summary>
        /// 账户
        /// </summary>
        public DbSet<Account> Accounts { get; set; }

        public DbSet<Classroom> Classroom { get; set; }

        /// <summary>
        /// 设备
        /// </summary>
        public DbSet<Equip> Equips { get; set; }

        /// <summary>
        /// 宿舍
        /// </summary>
        public DbSet<Hostel> Hostels { get; set; }
        /// <summary>
        /// 教师
        /// </summary>
        public DbSet<Teacher> Teachers { get; set; }

        /// <summary>
        /// 课程表
        /// </summary>
        public DbSet<TimeTable> TimeTables { get; set; }

        public DbSet<TeacherAttender> TeacherAttender { get; set; }

        /// <summary>
        /// 设备维修
        /// </summary>
        public DbSet<EquipMaintenance> EquipMaintenances { get; set; }

        /// <summary>
        /// 缴费记录
        /// </summary>
        public DbSet<PayInfo> PayInfo { get; set; }

        /// <summary>
        /// 宿舍管理员
        /// </summary>
        public DbSet<DormitoryManager> DormitoryManagers { get; set; }
        /// <summary>
        /// 设备报备
        /// </summary>
        public DbSet<Reporting> Reportings { get; set; }

        /// <summary>
        /// 数据库表创建事件
        /// </summary>
        /// <param name="modelBuilder">模型实体创建器</param>
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            // 程序初始化,数据表刚刚正在创建时,填充默认数据
            modelBuilder.Entity<Department>()
                .HasData(EntityInitData.departments);
            modelBuilder.Entity<Account>()
                .HasData(EntityInitData.accounts);
            modelBuilder.Entity<Student>()
                .HasData(EntityInitData.students);
            modelBuilder.Entity<Equip>()
                .HasData(EntityInitData.equips);
            modelBuilder.Entity<Classroom>()
                .HasData(EntityInitData.classroom);
            modelBuilder.Entity<Teacher>()
                .HasData(EntityInitData.teachers);
            //modelBuilder.Entity<DormitoryManager>()
            //    .HasData(EntityInitData.DormitoryManagers);
            modelBuilder.Entity<EquipMaintenance>()
                .HasData(EntityInitData.EquipMaintenances);
            modelBuilder.Entity<TeacherAttender>()
                .HasData(EntityInitData.teacherattender);
            modelBuilder.Entity<PayInfo>()
                .HasData(EntityInitData.payInfos);
            modelBuilder.Entity<TimeTable>()
               .HasData(EntityInitData.timetables);
            modelBuilder.Entity<Reporting>()
                 .HasData(EntityInitData.Reportings);

        }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            base.OnConfiguring(optionsBuilder);
        }
    }
}
